<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="220px">
      <el-form-item label="拼团首页下热门拼团的中文提示">
        <el-input v-model="form.coupon_in_hot_title" />
      </el-form-item>
      <el-form-item label="拼团列表页标题的中文提示">
        <el-input v-model="form.coupon_list_title" />
      </el-form-item>
      <el-form-item label="拼团详情页下拼团说明的中文提示">
        <el-input v-model="form.coupon_intro_in_details"/>
      </el-form-item>
      <el-form-item label="金豆奖励">
        <el-input v-model="form.coupon_rebate_in_details" />
      </el-form-item>
      <el-form-item label="他人拼团的中文提示">
        <el-col :span="4">
          <el-input v-model="form.coupon_wait_for_coupon_list" />
        </el-col>
      </el-form-item>
      <el-form-item label="他们正在等人拼单页面标题的中文提示">
        <el-col :span="4">
          <el-input v-model="form.coupon_wait_for_coupon_title" />
        </el-col>
      </el-form-item>
      <el-form-item label="拼团详情的中文提示">
        <el-col :span="4">
          <el-input v-model="form.coupon_button" />
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">Create</el-button>
        <el-button @click="onCancel">Cancel</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getSettings, editSettings } from '@/api/system'
import { Message } from 'element-ui'

export default {
  data() {
    return {
      form: {
        coupon_in_hot_title: '',
        coupon_list_title: '',
        coupon_intro_in_details: '',
        coupon_rebate_in_details: '',
        coupon_wait_for_coupon_list: '',
        coupon_wait_for_coupon_title: '',
        coupon_button: ''
      }
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    getInfo() {
      getSettings({ id: 1 }).then(resp => {
        const { data } = resp
        this.form = {
          id: 1,
          coupon_in_hot_title: data.coupon_in_hot_title,
          coupon_list_title: data.coupon_list_title,
          coupon_intro_in_details: data.coupon_intro_in_details,
          coupon_rebate_in_details: data.coupon_rebate_in_details,
          coupon_wait_for_coupon_list: data.coupon_wait_for_coupon_list,
          coupon_wait_for_coupon_title: data.coupon_wait_for_coupon_title,
          coupon_button: data.coupon_button
        }
      }).catch(error => {
        Message({
          message: error.response.data.errmsg,
          type: 'error',
          duration: 5 * 1000
        })
      })
    },
    onSubmit() {
      editSettings(this.form).then(() => {
        this.$notify({
          title: '编辑成功',
          type: 'success',
          message: '编辑成功',
          duration: 2000
        })
        this.getInfo()
      }).catch(error => {
        this.$notify({
          title: '编辑失败',
          type: 'error',
          message: error.errmsg,
          duration: 2000
        })
      })
    },
    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      })
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

